package cn.initcap.controller;

import cn.initcap.dto.User;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * @author initcap
 * @date Created in 2018/5/17 PM10:15.
 */
@Controller
public class UserController {

    @Autowired
    private ProviderSignInUtils providerSignInUtils;

    @GetMapping("/regist")
    public void regist(User user, HttpServletRequest request) {
        //不管是注册用户还是绑定用户，都会拿到一个用户唯一标识。
        String userId = user.getUsername();
        providerSignInUtils.doPostSignUp(userId, new ServletWebRequest(request));
    }

    @GetMapping("/signin.page")
    public String signin() {
        return "signin";
    }

    @GetMapping("signup.page")
    public String signup() {
        return "signup";
    }

    @GetMapping("/index.page")
    public String index() {
        return "index";
    }
}
